import 'package:eyepetizer_example/model/paging_model.dart';

/// nextPageUrl : "http://baobab.kaiyanapp.com/api/v2/feed?date=1666054800000&num=1"
/// nextPublishTime : 1666227600000
/// newestIssueType : "morning"
/// dialog : null

class CommonItem extends PagingModel<ItemList>{
  CommonItem({
    List<IssueList>? issueList,
    String? nextPageUrl,
    num? nextPublishTime,
    String? newestIssueType,
    dynamic dialog,
  }) {
    _issueList = issueList;
    _nextPageUrl = nextPageUrl;
    _nextPublishTime = nextPublishTime;
    _newestIssueType = newestIssueType;
    _dialog = dialog;
  }

  CommonItem.fromJson(dynamic json) {
    if (json['issueList'] != null) {
      _issueList = [];
      json['issueList'].forEach((v) {
        _issueList?.add(IssueList.fromJson(v));
      });
    }
    _nextPageUrl = json['nextPageUrl'];
    _nextPublishTime = json['nextPublishTime'];
    _newestIssueType = json['newestIssueType'];
    _dialog = json['dialog'];
    nextPageUrl = _nextPageUrl;

    if(_issueList != null) {
      var iList = _issueList?[0].itemList;
      if(iList != null) {
        itemList = iList;
      }
    }

  }

  List<IssueList>? _issueList;
  String? _nextPageUrl;
  num? _nextPublishTime;
  String? _newestIssueType;
  dynamic _dialog;

  CommonItem copyWith({
    List<IssueList>? issueList,
    String? nextPageUrl,
    num? nextPublishTime,
    String? newestIssueType,
    dynamic dialog,
  }) =>
      CommonItem(
        issueList: issueList ?? _issueList,
        nextPageUrl: nextPageUrl ?? _nextPageUrl,
        nextPublishTime: nextPublishTime ?? _nextPublishTime,
        newestIssueType: newestIssueType ?? _newestIssueType,
        dialog: dialog ?? _dialog,
      );

  List<IssueList>? get issueList => _issueList;

  String? get nextPageUrl => _nextPageUrl;

  num? get nextPublishTime => _nextPublishTime;

  String? get newestIssueType => _newestIssueType;

  dynamic get dialog => _dialog;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    if (_issueList != null) {
      map['issueList'] = _issueList?.map((v) => v.toJson()).toList();
    }
    map['nextPageUrl'] = _nextPageUrl;
    map['nextPublishTime'] = _nextPublishTime;
    map['newestIssueType'] = _newestIssueType;
    map['dialog'] = _dialog;
    return map;
  }
}

/// releaseTime : 1666141200000
/// type : "morning"
/// date : 1666141200000
/// publishTime : 1666141200000
/// count : 10

class IssueList extends PagingModel<ItemList> {
  IssueList({
    num? releaseTime,
    String? type,
    num? date,
    num? publishTime,
    List<ItemList>? itemList,
    num? count,
    String? nextPageUrl,
    int? total,
  }) {
    _releaseTime = releaseTime;
    _type = type;
    _date = date;
    _publishTime = publishTime;
    _itemList = itemList;
    _count = count;
    _nextPageUrl = nextPageUrl;
    _total = total;
  }

  IssueList.fromJson(dynamic json) {
    _total = json['total'];
    _releaseTime = json['releaseTime'];
    _type = json['type'];
    _date = json['date'];
    _publishTime = json['publishTime'];
    if (json['itemList'] != null) {
      _itemList = [];
      json['itemList'].forEach((v) {
        _itemList?.add(ItemList.fromJson(v));
      });

      itemList = _itemList??[];
    }
    _count = json['count'];
    _nextPageUrl = json['nextPageUrl'];
  }

  num? _releaseTime;
  String? _type;
  num? _date;
  num? _publishTime;
  List<ItemList>? _itemList;
  num? _count;
  String? _nextPageUrl;
  int? _total;

  IssueList copyWith({
    num? releaseTime,
    String? type,
    num? date,
    num? publishTime,
    List<ItemList>? itemList,
    num? count,
    String? nextPageUrl,
    int? total,
  }) =>
      IssueList(
        releaseTime: releaseTime ?? _releaseTime,
        type: type ?? _type,
        date: date ?? _date,
        publishTime: publishTime ?? _publishTime,
        itemList: itemList ?? _itemList,
        count: count ?? _count,
        nextPageUrl: nextPageUrl?? _nextPageUrl,
        total: total?? _total,
      );

  int? get total=> _total;
  String? get nextPageUrl=> _nextPageUrl;
  num? get releaseTime => _releaseTime;

  String? get type => _type;

  num? get date => _date;

  num? get publishTime => _publishTime;

  List<ItemList>? get getItemList => _itemList;

  num? get count => _count;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['releaseTime'] = _releaseTime;
    map['type'] = _type;
    map['date'] = _date;
    map['publishTime'] = _publishTime;
    if (_itemList != null) {
      map['itemList'] = _itemList?.map((v) => v.toJson()).toList();
    }
    map['count'] = _count;
    map['nextPageUrl'] = _nextPageUrl;
    map['total'] = _total;
    return map;
  }
}

/// type : "banner2"
/// data : {"dataType":"Banner","id":0,"title":"","description":"","image":"http://img.kaiyanapp.com/eef24aa10ab6cf17b5a512943ec22053.jpeg?imageMogr2/quality/60/format/jpg","actionUrl":"","adTrack":null,"shade":false,"label":null,"labelList":null,"header":null,"autoPlay":false}
/// trackingData : null
/// tag : null
/// id : 0
/// adIndex : -1

class ItemList {
  ItemList({
    String? type,
    Data? data,
    dynamic trackingData,
    dynamic tag,
    num? id,
    num? adIndex,
  }) {
    _type = type;
    _data = data;
    _trackingData = trackingData;
    _tag = tag;
    _id = id;
    _adIndex = adIndex;
  }

  ItemList.fromJson(dynamic json) {
    _type = json['type'];
    _data = json['data'] != null ? Data.fromJson(json['data']) : null;
    _trackingData = json['trackingData'];
    _tag = json['tag'];
    _id = json['id'];
    _adIndex = json['adIndex'];
  }

  String? _type;
  Data? _data;
  dynamic _trackingData;
  dynamic _tag;
  num? _id;
  num? _adIndex;

  ItemList copyWith({
    String? type,
    Data? data,
    dynamic trackingData,
    dynamic tag,
    num? id,
    num? adIndex,
  }) =>
      ItemList(
        type: type ?? _type,
        data: data ?? _data,
        trackingData: trackingData ?? _trackingData,
        tag: tag ?? _tag,
        id: id ?? _id,
        adIndex: adIndex ?? _adIndex,
      );

  String? get type => _type;

  Data? get data => _data;

  dynamic get trackingData => _trackingData;

  dynamic get tag => _tag;

  num? get id => _id;

  num? get adIndex => _adIndex;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['type'] = _type;
    if (_data != null) {
      map['data'] = _data?.toJson();
    }
    map['trackingData'] = _trackingData;
    map['tag'] = _tag;
    map['id'] = _id;
    map['adIndex'] = _adIndex;
    return map;
  }
}

/// dataType : "Banner"
/// id : 0
/// title : ""
/// description : ""
/// image : "http://img.kaiyanapp.com/eef24aa10ab6cf17b5a512943ec22053.jpeg?imageMogr2/quality/60/format/jpg"
/// actionUrl : ""
/// adTrack : null
/// shade : false
/// label : null
/// labelList : null
/// header : null
/// autoPlay : false

class Data {
  Data({
    String? dataType,
    int? id,
    String? title,
    String? description,
    String? image,
    String? actionUrl,
    dynamic adTrack,
    bool? shade,
    dynamic label,
    dynamic labelList,
    Header? header,
    bool? autoPlay,
    Cover? cover,
    String? text,
    String? category,
    int? duration,
    Author? author,
    Provide? provide,
    String? playUrl,
    List<ItemList>? itemList,
    Consumption? consumption,
    List<Tag>? tags,
  }) {
    _dataType = dataType;
    _id = id;
    _title = title;
    _description = description;
    _image = image;
    _actionUrl = actionUrl;
    _adTrack = adTrack;
    _shade = shade;
    _label = label;
    _labelList = labelList;
    _header = header;
    _autoPlay = autoPlay;
    _cover = cover;
    _text = text;
    _category = category;
    _duration = duration;
    _author = author;
    _provide = provide;
    _playUrl = playUrl;
    _itemList = itemList;
    _consumption = consumption;
    _tags = tags;
  }

  Data.fromJson(dynamic json) {
    _dataType = json['dataType'];
    _id = json['id'];
    _title = json['title'];
    _description = json['description'];
    _image = json['image'];
    _actionUrl = json['actionUrl'];
    _adTrack = json['adTrack'];
    _shade = json['shade'];
    _label = json['label'];
    _labelList = json['labelList'];
    _header = json['header'] != null ? Header.fromJson(json['header']) : null;
    _autoPlay = json['autoPlay'];
    _cover = json['cover'] != null ? Cover.fromJson(json['cover']) : null;
    _text = json['text'];
    _category = json['category'];
    _duration = json['duration'];
    _author = json['author'] != null ? Author.fromJson(json['author']) : null;
    _provide = json['provide'] != null ? Provide.fromJson(json['provide']) : null;
    _playUrl = json['playUrl'];
    _consumption = json['consumption'] != null ? Consumption.fromJson(json['consumption']) : null;
    if (json['itemList'] != null) {
      _itemList = [];
      json['itemList'].forEach((v) {
        _itemList?.add(ItemList.fromJson(v));
      });
    }

    if (json['tags'] != null) {
      _tags = [];
      for (var v in (json['tags'] as List)) {
        _tags?.add(Tag.fromJson(v));
      }
    }
  }

  List<ItemList>? _itemList;
  String? _dataType;
  int? _id;
  String? _title;
  String? _description;
  String? _image;
  String? _actionUrl;
  dynamic _adTrack;
  bool? _shade;
  dynamic _label;
  dynamic _labelList;
  Header? _header;
  bool? _autoPlay;
  Cover? _cover;
  String? _text;
  String time = DateTime.now().toString();
  String? _category;
  int? _duration;
  Author? _author;
  Provide? _provide;
  String ? _playUrl;
  Consumption? _consumption;
  List<Tag>? _tags;

  Data copyWith({
    String? dataType,
    int? id,
    String? title,
    String? description,
    String? image,
    String? actionUrl,
    dynamic adTrack,
    bool? shade,
    dynamic label,
    dynamic labelList,
    Header? header,
    bool? autoPlay,
    Provide? provide,
    String? playUrl,
    List<ItemList>? itemList,
    Consumption? consumption,
    List<Tag>? tags,
  }) =>
      Data(
        dataType: dataType ?? _dataType,
        id: id ?? _id,
        title: title ?? _title,
        description: description ?? _description,
        image: image ?? _image,
        actionUrl: actionUrl ?? _actionUrl,
        adTrack: adTrack ?? _adTrack,
        shade: shade ?? _shade,
        label: label ?? _label,
        labelList: labelList ?? _labelList,
        header: header ?? _header,
        autoPlay: autoPlay ?? _autoPlay,
        cover: cover ?? _cover,
        text: text ?? _text,
        category: category ?? _category,
        duration: duration ?? _duration,
        author: author ?? _author,
        provide: provide ?? _provide,
        playUrl: playUrl ?? _playUrl,
        consumption: consumption ?? _consumption,
        itemList: itemList ?? _itemList,
        tags: tags ?? _tags,
      );

  List<Tag>? get tags => _tags;
  Consumption? get consumption => _consumption;
  String? get playUrl => _playUrl;
  Provide? get provide => _provide;
  Author? get author => _author;
  int? get duration => _duration;
  String? get dataType => _dataType;
  List<ItemList>? get itemList => _itemList;

  int? get id => _id;

  String? get title => _title;

  String? get description => _description;

  String? get image => _image;

  String? get actionUrl => _actionUrl;

  dynamic get adTrack => _adTrack;

  bool? get shade => _shade;

  dynamic get label => _label;

  dynamic get labelList => _labelList;

  Header? get header => _header;

  bool? get autoPlay => _autoPlay;
  Cover? get cover => _cover;
  String? get text => _text;
  String? get category => _category;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['dataType'] = _dataType;
    map['id'] = _id;
    map['title'] = _title;
    map['description'] = _description;
    map['image'] = _image;
    map['actionUrl'] = _actionUrl;
    map['adTrack'] = _adTrack;
    map['shade'] = _shade;
    map['label'] = _label;
    map['labelList'] = _labelList;
    map['header'] = _header;
    map['autoPlay'] = _autoPlay;
    map['cover'] = _cover;
    map['text'] = _text;
    map['category'] = _category;
    map['duration'] = _duration;
    map['author'] = _author;
    map['provide'] = _provide;
    map['playUrl'] = _playUrl;
    map['consumption'] = _consumption;
    if (_itemList != null) {
      map['itemList'] = _itemList?.map((v) => v.toJson()).toList();
    }
    map['tags'] = _tags;
    return map;
  }
}

class Consumption {
  int? shareCount;
  int? replyCount;
  int? collectionCount;

  Consumption({this.shareCount, this.replyCount, this.collectionCount});

  Consumption.fromJson(Map<String, dynamic> json) {
    shareCount = json['shareCount'];
    replyCount = json['replyCount'];
    collectionCount = json['collectionCount'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['shareCount'] = shareCount;
    data['replyCount'] = replyCount;
    data['collectionCount'] = collectionCount;
    return data;
  }
}

class Cover {
  String? feed;
  String? detail;
  String? blurred;
  String? homepage;

  Cover({this.feed, this.detail, this.blurred, this.homepage});

  Cover.fromJson(Map<String, dynamic> json) {
    feed = json['feed'];
    detail = json['detail'];
    blurred = json['blurred'];
    homepage = json['homepage'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['feed'] = feed;
    data['detail'] = detail;
    data['blurred'] = blurred;
    data['homepage'] = homepage;
    return data;
  }
}

class Author {
  IssueIssuelistItemlistDataAuthorShield? shield;
  bool? expert;
  int? approvedNotReadyVideoCount;
  String? icon;
  String? link;
  String? description;
  int? videoNum;
  IssueIssuelistItemlistDataAuthorFollow? follow;
  int? recSort;
  bool? ifPgc;
  String? name;
  int? latestReleaseTime;
  int? id;

  Author(
      {this.shield,
        this.expert,
        this.approvedNotReadyVideoCount,
        this.icon,
        this.link,
        this.description,
        this.videoNum,
        this.follow,
        this.recSort,
        this.ifPgc,
        this.name,
        this.latestReleaseTime,
        this.id});

  Author.fromJson(Map<String, dynamic> json) {
    shield = json['shield'] != null
        ? IssueIssuelistItemlistDataAuthorShield.fromJson(json['shield'])
        : null;
    expert = json['expert'];
    approvedNotReadyVideoCount = json['approvedNotReadyVideoCount'];
    icon = json['icon'];
    link = json['link'];
    description = json['description'];
    videoNum = json['videoNum'];
    follow = json['follow'] != null
        ? IssueIssuelistItemlistDataAuthorFollow.fromJson(json['follow'])
        : null;
    recSort = json['recSort'];
    ifPgc = json['ifPgc'];
    name = json['name'];
    latestReleaseTime = json['latestReleaseTime'];
    id = json['id'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (shield != null) {
      data['shield'] = shield!.toJson();
    }
    data['expert'] = expert;
    data['approvedNotReadyVideoCount'] = approvedNotReadyVideoCount;
    data['icon'] = icon;
    data['link'] = link;
    data['description'] = description;
    data['videoNum'] = videoNum;
    if (follow != null) {
      data['follow'] = follow!.toJson();
    }
    data['recSort'] = recSort;
    data['ifPgc'] = ifPgc;
    data['name'] = name;
    data['latestReleaseTime'] = latestReleaseTime;
    data['id'] = id;
    return data;
  }
}

class IssueIssuelistItemlistDataAuthorShield {
  int? itemId;
  String? itemType;
  bool? shielded;

  IssueIssuelistItemlistDataAuthorShield(
      {this.itemId, this.itemType, this.shielded});

  IssueIssuelistItemlistDataAuthorShield.fromJson(Map<String, dynamic> json) {
    itemId = json['itemId'];
    itemType = json['itemType'];
    shielded = json['shielded'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['itemId'] = itemId;
    data['itemType'] = itemType;
    data['shielded'] = shielded;
    return data;
  }
}

class IssueIssuelistItemlistDataAuthorFollow {
  int? itemId;
  String? itemType;
  bool? followed;

  IssueIssuelistItemlistDataAuthorFollow(
      {this.itemId, this.itemType, this.followed});

  IssueIssuelistItemlistDataAuthorFollow.fromJson(Map<String, dynamic> json) {
    itemId = json['itemId'];
    itemType = json['itemType'];
    followed = json['followed'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['itemId'] = itemId;
    data['itemType'] = itemType;
    data['followed'] = followed;
    return data;
  }
}

class Provide {
  String? icon;
  String? name;
  String? alias;

  Provide({this.icon, this.name, this.alias});

  Provide.fromJson(Map<String, dynamic> json) {
    icon = json['icon'];
    name = json['name'];
    alias = json['alias'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['icon'] = icon;
    data['name'] = name;
    data['alias'] = alias;
    return data;
  }
}

class Header {
  String? actionUrl;
  String? description;
  bool? expert;
  String? icon;
  String? iconType;
  int? id;
  bool? ifPgc;
  bool? ifShowNotificationIcon;
  String? title;
  int? uid;

  Header(
      {this.actionUrl,
        this.description,
        this.expert,
        this.icon,
        this.iconType,
        this.id,
        this.ifPgc,
        this.ifShowNotificationIcon,
        this.title,
        this.uid});

  Header.fromJson(Map<String, dynamic> json) {
    actionUrl = json['actionUrl'];
    description = json['description'];
    expert = json['expert'];
    icon = json['icon'];
    iconType = json['iconType'];
    id = json['id'];
    ifPgc = json['ifPgc'];
    ifShowNotificationIcon = json['ifShowNotificationIcon'];
    title = json['title'];
    uid = json['uid'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['actionUrl'] = actionUrl;
    data['description'] = description;
    data['expert'] = expert;
    data['icon'] = icon;
    data['iconType'] = iconType;
    data['id'] = id;
    data['ifPgc'] = ifPgc;
    data['ifShowNotificationIcon'] = ifShowNotificationIcon;
    data['title'] = title;
    data['uid'] = uid;
    return data;
  }
}

class Tag {
  String? tagRecType;
  String? headerImage;
  String? actionUrl;
  int? communityIndex;
  String? name;
  int? id;
  String? bgPicture;

  Tag(
      {this.tagRecType,
        this.headerImage,
        this.actionUrl,
        this.communityIndex,
        this.name,
        this.id,
        this.bgPicture});

  Tag.fromJson(Map<String, dynamic> json) {
    tagRecType = json['tagRecType'];
    headerImage = json['headerImage'];
    actionUrl = json['actionUrl'];
    communityIndex = json['communityIndex'];
    name = json['name'];
    id = json['id'];
    bgPicture = json['bgPicture'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['tagRecType'] = tagRecType;
    data['headerImage'] = headerImage;
    data['actionUrl'] = actionUrl;
    data['communityIndex'] = communityIndex;
    data['name'] = name;
    data['id'] = id;
    data['bgPicture'] = bgPicture;
    return data;
  }

}
